'use strict';

/**
 * Created by twer on 15/4/12.
 */
angular.module('common').controller('ProfileCtrl', [
    '$scope',
    'ProfilePhotoService',
    'ProfileInfoService',
    'PhotoHost',
    '$routeParams',
    'FriendAddModalService',
    '$rootScope',
    'FileService',
    function ($scope, ProfilePhotoService, ProfileInfoService, PhotoHost, $routeParams, FriendAddModalService, $rootScope, FileService) {
        ProfilePhotoService.query({userId: $routeParams.userId}, function (response) {
            setPhoto(response.photoId);
        });

        function setPhoto(photoId) {
            $scope.profilePhotoUri = PhotoHost + 'cdrmimg/' + photoId + '?w=160&h=160';
        }

        ProfileInfoService.query({userId: $routeParams.userId}, function (response) {
            $rootScope.visitedUserName = response.name;
        });

        $scope.addFriend = FriendAddModalService.activate;

        $scope.$on('ProfilePhotoUploadedEvent', function (e, photoId) {
            setPhoto(photoId);
        });
    }]);